package com.xiaoyaoji.postman.pojo.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AccessLevel;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;

import java.util.List;
import java.util.Map;

/**
 * @author liyacai
 * @description
 * @date 2020-06-14
 */
@Data
@Accessors(chain = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
public class PostmanDTO {

    InfoBean info;
    List<ItemBean> item;

    @Data
    @Accessors(chain = true)
    @FieldDefaults(level = AccessLevel.PRIVATE)
    public static class InfoBean {

        /**
         * 文件名
         */
        String name;

        /**
         * 格式
         */
        String schema = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json";

    }

    @Data
    @Accessors(chain = true)
    @FieldDefaults(level = AccessLevel.PRIVATE)
    public static class ItemBean {

        /**
         * 接口名称
         */
        String name;

        /**
         * 请求体
         */
        RequestBean request;

        @Data
        @Accessors(chain = true)
        @FieldDefaults(level = AccessLevel.PRIVATE)
        public static class RequestBean {

            /**
             * 请求类型
             */
            String method;
            /**
             * 请求地址
             */
            UrlBean url;

            /**
             * 请求体
             */
            BodyBean body;

            @Data
            @Accessors(chain = true)
            @FieldDefaults(level = AccessLevel.PRIVATE)
            public static class UrlBean {
                /**
                 * 请求地址
                 */
                String path;

                /**
                 * 请求体
                 */
                List<QueryBean> query;

                @Data
                @Accessors(chain = true)
                @FieldDefaults(level = AccessLevel.PRIVATE)
                public static class QueryBean {
                    String key;
                    String value;
                }
            }

            @Data
            @Accessors(chain = true)
            @FieldDefaults(level = AccessLevel.PRIVATE)
            public static class BodyBean {

                String mode = "raw";

                /**
                 * 请求json
                 */
                String raw;

                OptionsBean options = new OptionsBean();

                @Data
                @Accessors(chain = true)
                @FieldDefaults(level = AccessLevel.PRIVATE)
                public static class OptionsBean {

                    RawBean raw = new RawBean();

                    @Data
                    @Accessors(chain = true)
                    @FieldDefaults(level = AccessLevel.PRIVATE)
                    public static class RawBean {
                        String language = "json";
                    }
                }
            }

        }
    }
}
